package cn.iocoder.yudao.module.biz.service.licenceSafeMeasuresSetting;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.biz.controller.admin.licenceSafeMeasuresSetting.vo.BizLicenceSafeMeasuresSettingCreateReqVO;
import cn.iocoder.yudao.module.biz.controller.admin.licenceSafeMeasuresSetting.vo.BizLicenceSafeMeasuresSettingExportReqVO;
import cn.iocoder.yudao.module.biz.controller.admin.licenceSafeMeasuresSetting.vo.BizLicenceSafeMeasuresSettingPageReqVO;
import cn.iocoder.yudao.module.biz.controller.admin.licenceSafeMeasuresSetting.vo.BizLicenceSafeMeasuresSettingUpdateReqVO;
import cn.iocoder.yudao.module.biz.convert.licenceSafeMeasuresSetting.BizLicenceSafeMeasuresSettingConvert;
import cn.iocoder.yudao.module.biz.dal.dataobject.licenceSafeMeasuresSetting.BizLicenceSafeMeasuresSettingDO;
import cn.iocoder.yudao.module.biz.dal.mysql.licenceSafeMeasuresSetting.BizLicenceSafeMeasuresSettingMapper;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;

import javax.annotation.Resource;
import java.util.Collection;
import java.util.List;

/**
 * 危险作业票安全措施配置 Service 实现类
 *
 * @author 芋道源码
 */
@Service
@Validated
public class BizLicenceSafeMeasuresSettingServiceImpl implements BizLicenceSafeMeasuresSettingService {

    @Resource
    private BizLicenceSafeMeasuresSettingMapper licenceSafeMeasuresSettingMapper;

    @Override
    public String createLicenceSafeMeasuresSetting(BizLicenceSafeMeasuresSettingCreateReqVO createReqVO) {
        // 插入
        BizLicenceSafeMeasuresSettingDO licenceSafeMeasuresSetting = BizLicenceSafeMeasuresSettingConvert.INSTANCE.convert(createReqVO);
        licenceSafeMeasuresSettingMapper.insert(licenceSafeMeasuresSetting);
        // 返回
        return licenceSafeMeasuresSetting.getId();
    }

    @Override
    public void updateLicenceSafeMeasuresSetting(BizLicenceSafeMeasuresSettingUpdateReqVO updateReqVO) {
        // 校验存在
        this.validateLicenceSafeMeasuresSettingExists(updateReqVO.getId());
        // 更新
        BizLicenceSafeMeasuresSettingDO updateObj = BizLicenceSafeMeasuresSettingConvert.INSTANCE.convert(updateReqVO);
        licenceSafeMeasuresSettingMapper.updateById(updateObj);
    }

    @Override
    public void deleteLicenceSafeMeasuresSetting(String id) {
        // 校验存在
        this.validateLicenceSafeMeasuresSettingExists(id);
        // 删除
        licenceSafeMeasuresSettingMapper.deleteById(id);
    }

    private void validateLicenceSafeMeasuresSettingExists(String id) {
//        if (licenceSafeMeasuresSettingMapper.selectById(id) == null) {
//            throw exception(ErrorCodeConstants.LICENCE_SAFE_MEASURES_SETTING_NOT_EXISTS);
//        }
    }

    @Override
    public BizLicenceSafeMeasuresSettingDO getLicenceSafeMeasuresSetting(String id) {
        return licenceSafeMeasuresSettingMapper.selectById(id);
    }

    @Override
    public List<BizLicenceSafeMeasuresSettingDO> getLicenceSafeMeasuresSettingList(Collection<String> ids) {
        return licenceSafeMeasuresSettingMapper.selectBatchIds(ids);
    }

    @Override
    public PageResult<BizLicenceSafeMeasuresSettingDO> getLicenceSafeMeasuresSettingPage(BizLicenceSafeMeasuresSettingPageReqVO pageReqVO) {
        return licenceSafeMeasuresSettingMapper.selectPage(pageReqVO);
    }

    @Override
    public List<BizLicenceSafeMeasuresSettingDO> getLicenceSafeMeasuresSettingList(BizLicenceSafeMeasuresSettingExportReqVO exportReqVO) {
        return licenceSafeMeasuresSettingMapper.selectList(exportReqVO);
    }

    @Override
    public List<BizLicenceSafeMeasuresSettingDO> getLicenceSafeMeasuresSettingByType(Integer type) {
        return licenceSafeMeasuresSettingMapper.selectByType(type);
    }

}
